<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Http\Requests\UserInsertRequest;
use App\User;
use Hash;

use App\Http\Model\Goods;
use App\Http\Model\Type;


use DB;

class TypedetailsController extends Controller
{
    public function pub2(){
        $link = \DB::table('sad_link')->orderBy('order','asc')->get();
        return $link;
    }
    /**
     * 处理前台分类数据
     */
    static public function getCatePid($pid=0)
    {

        $ctype = new Type();

        $data = $ctype->where('pid',$pid)->get();
        
        $arr = [];

        foreach ($data as $key => $value) {
            
            $value['sub'] = self::getCatePid($value['id']);

            $arr[] = $value;
        }
        return $arr;

    }

    
    public function getShow(Request $request)
    {
        //
        $id = $request->id;

       
         $type = new Type();

        $details = $type->where('id',$id)->first();


        // $pid = $details->pid;

        $pid = $details['pid'];

        // dd($pid);


        $pname = $type->where('id',$pid)->first();

        //获取商品信息;
        $goods = new Goods();

        // $data = $goods->get()->toArray();

        $newest = $goods->orderBy('ctime')->take(3)->get();

        $count = $goods->where('tid',$id)->count();


        $count = $request -> input('count',3);
        $search = $request -> input('search','');
        $request = $request -> all();
        $data = $goods->where('tid',$id)->paginate($count);

        $laytype = self::getCatePid();
        $link = $this->pub2();
        return view('home.typedetails.index',compact('link','data','details','pname','count','sum','newest','request','laytype'));
    }

    

   
}
